package org.mili.ticketeer.service;

import org.mili.ticketeer.dao.DaoFactory;
import org.mili.ticketeer.dao.ModificationResult;
import org.mili.ticketeer.dao.StateDao;
import org.mili.ticketeer.dto.State;
import org.mili.ticketeer.util.Lambda;

import java.util.List;

public class StateService extends Service {
	private StateDao _stateDao = DaoFactory.getDao(StateDao.class);

    public ModificationResult delete(final State state) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _stateDao.delete(state);
            }
        });
    }

    public ModificationResult write(final State state) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _stateDao.write(state);
            }
        });
    }

    public State findByToken(final String token) throws ServiceException {
        return doReadInService(new Lambda<State>() {
            @Override
            public State exec(Object... params) throws Exception {
                return _stateDao.findByToken(token);
            }
        });
    }

    public State findById(final int id) throws ServiceException {
        return doReadInService(new Lambda<State>() {
            @Override
            public State exec(Object... params) throws Exception {
                return _stateDao.findById(id);
            }
        });
    }

    public List<State> getStates() throws ServiceException {
        return doReadInService(new Lambda<List<State>>() {
            @Override
            public List<State> exec(Object... params) throws Exception {
                return _stateDao.getStates();
            }
        });
    }

}
